/**

 * @author liuzx

 * 2014年7月16日

 */

package com.tmall.testgen.plugin.wizards.runinspring.listener;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Shell;

import com.tmall.testgen.plugin.views.vo.SpringTree;

public class CopyInputListener implements SelectionListener {
	TreeViewer parasTreeViewer;
	Shell shell;

	public CopyInputListener(TreeViewer parasTreeViewer, Shell shell) {
		this.parasTreeViewer = parasTreeViewer;
		this.shell = shell;
	}

	@Override
	public void widgetSelected(SelectionEvent e) {
		IStructuredSelection selection = (IStructuredSelection) parasTreeViewer
				.getSelection();
		SpringTree currentTree = (SpringTree) selection.getFirstElement();
		if (currentTree == null) {
			return;
		}
		Clipboard cp = new Clipboard(e.display);
		cp.setContents(new Object[] { currentTree.toString() },
				new Transfer[] { TextTransfer.getInstance() });
		cp.dispose();
	}

	@Override
	public void widgetDefaultSelected(SelectionEvent e) {
	}

}
